/*
 * =====================================================================================
 *
 *       Filename:  dispatcherThreadPoll.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  08/03/2012 08:45:30 PM
 *       Revision:  none
 *       Compiler:  gcc/g++
 *
 *         Author:  wangtengchao , wangtengchao AT gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */


#include "../concurrency/mutex.h"
#include <vector>
namespace inm
{
    namespace net
    {
        class Dispatcher;
        class Demultiplexer;
        class DispatcherThread;

        class DispatcherThreadPool
        {
        public:
            DispatcherThreadPool(int threadNum);
            ~DispatcherThreadPool();
            void setThreadNum(int num)
            {//can only be changed if the server is not starting.
                if(isStarted)
                {
                    threadNum_ = num;
                    dispatcherThreads_.resize(num);
                }
            }
            Dispatcher* getNextDispatcher();
            void start();
            void quit();

        private:
            int threadNum_;
            std::vector<DispatcherThread*> dispatcherThreads_;
            inm::concurrency::MutexLock mutex_;
            bool isStarted;
            int next_;
        };
    };
};
